package com.eastfair.projectcore.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.projectcore.dto.ExhibitionDTO;
import com.eastfair.projectcore.dto.ExhibitionPageQuery;
import com.eastfair.projectcore.dto.ExhibitionSaveDTO;
import com.eastfair.projectcore.dto.ExhibitionUpdateDTO;
import com.eastfair.projectcore.entity.Exhibition;
import com.eastfair.projectcore.service.ExhibitionService;
import com.eastfair.projectcore.service.ProjectDbService;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.projectcore.vo.ExhibitionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 *
 * </p>
 *
 * @author ligang
 * @date 2021-07-22
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/exhibition")
@Api(value = "Exhibition", tags = "")
public class ExhibitionController extends SuperController<ExhibitionService, Long, Exhibition, ExhibitionPageQuery, ExhibitionSaveDTO, ExhibitionUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private ExhibitionService exhibitionService;
    @Autowired
    private ProjectDbService projectDbService;

    @Override
    public void handlerResult(IPage<Exhibition> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<Exhibition> exhibitionList = list.stream().map((map) -> {
            Exhibition exhibition = Exhibition.builder().build();
            //TODO 请在这里完成转换
            return exhibition;
        }).collect(Collectors.toList());


        return R.success(baseService.saveBatch(exhibitionList));
    }


    /**
     * 添加展会
     *
     * @param exhibitionDTO
     * @return
     */
    @ApiOperation(value = "添加展会", notes = "添加展会")
    @PostMapping("/executeCreateExhibition")
    public R executeCreateCompany(@RequestBody @Validated({ExhibitionDTO.executeCreateExhibition.class}) ExhibitionDTO exhibitionDTO) {
        return baseService.executeCreateExhibition(exhibitionDTO);
    }

    /**
     * 修改展会
     *
     * @param exhibitionDTO
     * @return
     */
    @ApiOperation(value = "修改展会", notes = "修改展会")
    @PutMapping("/executeUpdExhibition")
    public R executeUpdCompany(@RequestBody @Validated({ExhibitionDTO.executeCreateExhibition.class}) ExhibitionDTO exhibitionDTO) {
        return baseService.executeUpdExhibition(exhibitionDTO);
    }


    /**
     * 查询单个展会
     *
     * @param id 主键id
     * @return
     */
    @GetMapping("/getAndRoleById/{id}")
    public R<ExhibitionVO> getAndRoleById(@PathVariable(value = "id") Long id) {
        return R.success(baseService.getAndRoleById(id));
    }

}
